package com.base.api.pubg.httpclient;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.base.api.pubg.enums.PUBG;
import com.base.api.pubg.enums.SERVER;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * PUBG请求客户端
 *
 * @author junw
 * @date 2018/5/12
 */
@Component
public class PUBGHttpClient extends BaseHttpClient {

    @Override
    public synchronized JSONObject getMatcheInfo(String matcheId) throws IOException {
        StringBuffer url = new StringBuffer(PUBG.MATCHES.getDesc());
        url.append("/");
        url.append(matcheId);
        Object result = requestApi(url.toString());
        if(result instanceof JSONObject){
            return (JSONObject) result;
        }
        return new JSONObject();
    }

    @Override
    public JSONArray getPlayersInfoById(String... playersId) {
        return null;
    }

    @Override
    public JSONObject getPlayersInfoByName(String... playerId) throws IOException {
        StringBuffer url = new StringBuffer(PUBG.PLAYERS.getDesc());
        url.append("?filter[playerNames]=");
        for(String name : playerId){
            url.append(name);
            url.append(",");
        }
        Object result = requestApi(url.substring(0, url.length() - 1));
        if(result instanceof JSONObject){
            return (JSONObject) result;
        }
        return new JSONObject();
    }

    @Override
    public JSONArray getPlayerSeasonInfo(String playerId, String seasonId) {
        return null;
    }

    @Override
    public JSONArray getAllSeasonsInfo() {
        return null;
    }

    @Override
    public synchronized JSONArray getTelemetry(String telemetryUrl) throws IOException {
        Object result = request(telemetryUrl);
        if(result instanceof JSONArray){
            return (JSONArray) result;
        }
        return new JSONArray();
    }
}
